#!/usr/bin/env python
# coding=utf-8
"""
@Author  : youjia - 卞志伟
@file    : week_report_clean_comment.py.py
@contact : bianzhiwei@iyoujia.com
@time    : 2019-07-19 14:26 
@Desc    : 保洁评论明细
@Software: PyCharm
"""
import os
import sys

# 当前文件的路径
pwd, filename = os.path.split(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
# 当前文件的前两级目录
grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
sys.path.append(pwd)
sys.path.append(father_path)
sys.path.append(grader_father)
from report_system.utils import df_util
from report_system.utils import mail_util
from report_system.utils import mailbox_util
from report_system.utils.log_util import log
from report_system.utils.development_util import debug
from report_system.report_specify.clean_comment_specify import clean_comment_month

if debug:
    receivers = 'dt@iyoujia.com'
    city_mails = mailbox_util.mails_test
else:
    receivers = 'chengxuezi@iyoujia.com;kf@iyoujia.com;yy@iyoujia.com;dt@iyoujia.com;'
    city_mails = mailbox_util.mails_all


def process(st=None, et=None):
    clean_comment_month_df = clean_comment_month(st=st, et=et)
    clean_comment_month_df = df_util.df_set_index(clean_comment_month_df, '城市')
    log.info('处理数据完成！')

    df_dict = {
        "保洁评论明细": clean_comment_month_df,

    }

    text = """  Dear All:
                    附件是本月已评论订单所对应的房屋的上一笔订单的保洁明细数据！
                    请查收！
                    
                如有问题！
                请联系dt@iyoujia.com
                """
    mail_util.distribute_mail(df_dict=df_dict, file_name='保洁评论明细', text=text, title="保洁评论明细",
                              receiver=receivers, engine='xlsxwriter',
                              city_mails=city_mails, city=True, na_rep='-', uuid='service')


def run():
    try:
        # process('2019-06-01','2019-06-30')
        process()
    except Exception as e:
        mail_util.error_mail("保洁评论明细", e.__str__())
        log.exception(e)


if __name__ == '__main__':
    run()
